<!DOCTYPE html>
<html>
  <head>
    <title>登录</title>
    <link href="/stylesheets/style.css" rel="stylesheet" />
  </head>
  <body>
    <div class="form-box">
        <form id="form">
            <input type="text"  name="username"  placeholder="请输入用户名">
            <input type="password" name="password"  placeholder="请输入密码">
            <input type="button"  onclick="mySubmit()" value="登录">
        </form>
        <div>没有帐号， <a href="/regist">立即注册</a></div>
    </div>
  </body>
  <script>
    var ws = new WebSocket("ws://localhost:3000/users/login");
    ws.onopen = function(){
       //ws.send("这是客户端发送的数据");
    };
    ws.onmessage = function (evt){ 
       alert("服务端数据："+evt.data);
    };
    function mySubmit(){   
      let formData = new FormData(document.getElementById('form'));
      let data = Object.fromEntries(formData.entries());
      ws.send(JSON.stringify(data));
      //let username = formData.get('username');
      //var name = document.getElementById('username').value;
      //var passwd = document.getElementById("password").value;
      //ws.send(JSON.stringify({username:name,password:passwd}));
    }
 </script>
</html>